package com.mti.epivisitemobile.controller
{
	import com.mti.epivisitemobile.medias.ImageView;
	import com.mti.epivisitemobile.medias.ImageViewMediator;
	import com.mti.epivisitemobile.medias.MediaListView;
	import com.mti.epivisitemobile.medias.MediaListViewMediator;
	import com.mti.epivisitemobile.medias.VideoView;
	import com.mti.epivisitemobile.medias.VideoViewMediator;
	import com.mti.epivisitemobile.view.*;
	
	import org.puremvc.as3.interfaces.IMediator;
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.command.SimpleCommand;
	
	import spark.components.View;
	
	public class MediateViewCommand extends SimpleCommand
	{
		/**
		 * Each View is destroyed once it is moved away from,
		 * thus Mediators must also be transient. Any existing 
		 * Mediator is removed, and a new one registered
		 * along with the new View. Any additional mediators 
		 * associated with the children of these Views should be
		 * registered and removed the onRegister() and onRemove()
		 * methods of the View's Mediator.
		 */
		override public function execute(note:INotification):void
		{
			var view:View = View(note.getBody());
			var mediator:IMediator = null;
			
			if (view is AboutView)
			{
				facade.removeMediator(AboutViewMediator.NAME);
				mediator = new AboutViewMediator(AboutView(view));
			}
			else if (view is EventView)
			{
				facade.removeMediator(EventViewMediator.NAME);
				mediator = new EventViewMediator(EventView(view));
			}
			else if (view is EventListView)
			{
				facade.removeMediator(EventListViewMediator.NAME);
				mediator = new EventListViewMediator(EventListView(view));
			}
			else if (view is HomeView)
			{
				facade.removeMediator(HomeViewMediator.NAME);
				mediator = new HomeViewMediator(HomeView(view));
			}
			else if (view is HtmlView)
			{
				facade.removeMediator(HtmlViewMediator.NAME);
				mediator = new HtmlViewMediator(HtmlView(view));
			}
			else if (view is ImageView)
			{
				facade.removeMediator(ImageViewMediator.NAME);
				mediator = new ImageViewMediator(ImageView(view));
			}
			else if (view is MapView)
			{
				facade.removeMediator(MapViewMediator.NAME);
				mediator = new MapViewMediator(MapView(view));
			}
			else if (view is MediaListView)
			{
				facade.removeMediator(MediaListViewMediator.NAME);
				mediator = new MediaListViewMediator(MediaListView(view));
			}
			else if (view is StartView)
			{
				facade.removeMediator(StartViewMediator.NAME);
				mediator = new StartViewMediator(StartView(view));
			}
			else if (view is QRDecodeView)
			{
				facade.removeMediator(QRDecodeViewMediator.NAME);
				mediator = new QRDecodeViewMediator(QRDecodeView(view));
			}
			else if (view is VideoView)
			{
				facade.removeMediator(VideoViewMediator.NAME);
				mediator = new VideoViewMediator(VideoView(view));
			}
			
			if (mediator != null)
				facade.registerMediator(mediator);
		}
	}
}